#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/wait.h>


int main()
{
  pid_t id = fork();
  if(id == 0)
  {
    //子进程
    int i = 3;
    int j = i / 0;
    printf("i am a child process\n");
    sleep(5);
    exit(0);
  }

  int status = 0;
  pid_t ret = waitpid(id,&status,0);
  if(ret > 0)
  {
    printf("子进程的退出信号为:%d\n",WIFEXITED(status));
    if(WIFEXITED(status))
    {
      printf("进程没有异常\n");
      if(WEXITSTATUS(status) == 0)
      {
        printf("进程正常执行退出\n");
      }
      else
      {
        printf("进程错误退出\n");
      }
    
    }
    else
    {
      printf("进程异常\n");
    }

  }
  




  return 0;
}
